

/* Kernel includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"

#include "LED1.h"
#include "LED2.h"
#include "LED3.h"
#include "AS1.h"
#include "AD1.h"

#include "utilidades.h"



xSemaphoreHandle xSemaphore;
xQueueHandle xQueue1;

extern void vTaskCode1( void * pvParameters );
extern void vTaskCode2( void * pvParameters );
extern void vTaskCode3( void * pvParameters );
extern void vTaskCode4( void * pvParameters );
extern void vTaskCode5( void * pvParameters );
extern void vTaskTimeOut( void * pvParameters );

xTaskHandle xHandle1;
xTaskHandle xHandle2;
xTaskHandle xHandle3;
xTaskHandle xHandle4;
xTaskHandle xHandle5;
xTaskHandle xHandleTimeOut;

void vMain( void )
{

  char msg[23];
  uint16_t size = 23;
 /* se crea el semaforo */
  vSemaphoreCreateBinary( xSemaphore );  
  
  
  /* se crea la cola */
  
  xQueue1 = xQueueCreate( 100, sizeof( word ) ); 
  if( xQueue1 == 0 ){msg = "la cola no fue creada\n";}
  else{msg = "Cola creada correcto \n";}
  //AS1_SendBlock(msg, sizeof(msg), &size );    
  
  /* se crean las tareas */
	xTaskCreate( vTaskCode1, "NAME", 50, NULL, tskIDLE_PRIORITY, &xHandle1 );
	xTaskCreate( vTaskCode2, "NAME", 50, NULL, tskIDLE_PRIORITY, &xHandle2 );
	xTaskCreate( vTaskCode3, "NAME", 50, NULL, tskIDLE_PRIORITY, &xHandle3 );
	xTaskCreate( vTaskCode4, "NAME", 50, NULL, tskIDLE_PRIORITY, &xHandle4 );
	xTaskCreate( vTaskCode5, "NAME", 50, NULL, tskIDLE_PRIORITY, &xHandle5 );
	xTaskCreate( vTaskTimeOut, "NAME", 50, NULL, tskIDLE_PRIORITY + 1, &xHandleTimeOut );
	
	
	/* All the tasks have been created - start the scheduler. */
	vTaskStartScheduler();
	
	/* Should not reach here! */
	for( ;; ) 
	{
	
	}
}

/*-----------------------------------------------------------*/

void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
{
	/* This will get called if a stack overflow is detected during the context
	switch.  Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
	problems within nested interrupts, but only do this for debug purposes as
	it will increase the context switch time. */

	( void ) pxTask;
	( void ) pcTaskName;

	for( ;; )
	{
	}
}

void vApplicationTickHook( void )
{

}

